package com.dragon.modules.yuegou.enums.code;

import com.dragon.common.constant.enums.IBusinessCode;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 会员业务状态码
 * 
 * @author 刘武
 *
 */
public enum MessageCode implements IBusinessCode {

	/**
	 * 模板名称不能重复
	 * */
	TEMPLATE_TITLE_EXISTS(10001,"模板名称不能重复"),
	/**
	 * 验证码错误
	 * */
	INVALID_VCODE(10002,"验证码错误"),

	SEND_FREQUENT(10003,"短信验证码发送过频繁"),

	BLOCK_ERROR_CODE(10004,"号码黑名单"),

	SEND_ERROR_CODE(10005,"发送数量超出同模板同号天发送次数上限"),

	VCODE_ERROR_CODE(10006,"验证码超出同模板同号码天发送上限"),

	NOTICE_UPPER_LIMIT(10007,"通知超出同模板同号码天发送上限"),

	MOBILE_ERROR(10008,"手机号格式错误"),
	
	TEMPLATE_NOT_FOUND(10009,"模板未找到"),

	SEND_CODE_ERROR(10010,"发送短信失败"),
	
	/**
	 * 状态码说明
	 */
	TODO(10000, "提示消息");
	
	private final Integer code;

	private final String message;

	private MessageCode(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public Integer getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	/**
	 * 把code转化为ResponseCode枚举
	 * 
	 * @param code 代码
	 * @return
	 */
	public static MessageCode from(Integer code) {
		if (code == null) {
			return null;
		}
		return CODE_MAP.get(code);
	}

	/**
	 * Code Map for ResponseCode
	 */
	private static final Map<Integer, MessageCode> CODE_MAP = Stream.of(MessageCode.values())
			.collect(Collectors.toMap(MessageCode::getCode, e -> e));
	
}
